<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>修改密码</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/jiazai.css">
    <style>
        .hea-con {
            padding: 10px 20px 0;
            font-size: 16px;
            color: white;
            opacity: .7;
        }
        
        .input-wrap {
            padding: 20px;
            box-sizing: border-box;
        }
        
        .input-wrap>input {
            width: 100%;
            box-sizing: border-box;
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .input-wrap>p:first-of-type {
            padding-top: 15px;
            color: #F25B5B;
            opacity: .7;
        }
        
        .input-wrap>p:last-of-type {
            margin-top: 25px;
            padding: 16px;
            text-align: center;
            font-size: 18px;
            color: white;
            background: #2590FE;
            opacity: .7;
            border-radius: 5px;
        }
        
        .invi-code {
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .invi-code>input {
            flex: 1 1 0;
            width: 100%;
            background: transparent;
            color: white;
        }
        
        .invi-code>span {
            flex: 0 0 80px;
            color: #2590FE;
            font-size: 13px;
            text-align: right;
            opacity: .7;
        }
    </style>
</head>

<body style="background:#2a2c35;">
    <div id='app'>


        <!-- 加载中动画 -->
        <div id='jiazai-ani' v-if='jiazai'>
            <div class="arc"></div>
            <h1><span>LOADING</span></h1>
        </div>
        <!-- 加载中动画 -->

        <div class='hea-con dis-spa'>
            <img @click='_close()' src="./img/left.svg" width="22px" height="22px">
            <span v-text='title'>
                修改密码
            </span>
            <span style="opacity:0">1</span>
        </div>

        <div class='input-wrap'>
            <input type="text" placeholder="输入用户名" v-model='nickname'>
            <input type="text" placeholder="手机号" v-model='phone'>
            <div class='invi-code dis-spa'>
                <input type="text" placeholder="输入验证码" v-model='code'>
                <span @click='sendCode' v-text='codeFont' :style="{'color':codeFont!='获取验证码'?'#AAAAAA':''}">获取验证码</span>
            </div>
            <input type="password" placeholder="由8-20位字母或数字组成" v-model='pas1'>
            <input type="password" placeholder="确认密码" v-model='pas2'>
            <p class='dis-spa'>
                <span v-text='notice'>提示：输入密码有误</span>
            </p>
            <p @click='sure'>确认修改</p>
        </div>
    </div>
    <script src="js/comm.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/jquery.min.js"></script>
    <script>
        //是忘记密码进来的
        var forgetPass = function() {
            app.$data.title = '忘记密码';
        };
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                //获取验证码控制字
                codeFont: '获取验证码',
                //页面title  默认修改密码  有可能是忘记密码
                title: '修改密码',
                phone: '',
                code: '',
                pas1: '',
                pas2: '',
                notice: '',
                yanCode: '',
                nickname: ''
            },
            methods: {
                //获取验证码计时
                setTime: function() {
                    var This = this;
                    This.jiazai = true;
                    _post(DUANXIN, {
                        mobile: this.phone,
                        type: 3
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            // This.yanCode = data.back;
                            var num = 60;
                            var time = setInterval(function() {
                                if (num-- <= 1) {
                                    clearInterval(time);
                                    This.codeFont = '获取验证码';
                                } else {
                                    This.codeFont = '再次获取' + num + 's';
                                }
                            }, 1000);
                        } else {
                            _toast(data.msg);
                        }
                    });
                },
                //发送验证码
                sendCode: function() {
                    if (this.codeFont != '获取验证码') {
                        return;
                    }
                    if (!_checkMobile(this.phone)) {
                        _toast('请输入正确的手机号');
                        return;
                    }
                    this.setTime();
                },
                //确认
                sure: function() {
                    if (!_checkMobile(this.phone)) {
                        this.notice = '请输入正确的手机号';
                        return;
                    }
                    if (!this.code) {
                        this.notice = '请输入有效的验证码';
                        return;
                    }
                    if (this.pas1.lenth < 8 || this.pas1.length > 20) {
                        this.notice = '请输入8-20位字母或数字的密码';
                        return;
                    }
                    if (this.pas1 != this.pas2) {
                        this.notice = '两次密码输入不一致';
                        return;
                    }
                    this.jiazai = true;
                    var This = this;
                    _post(EDIT_LOGIN_PAS, {
                        userphone: This.phone,
                        password1: This.pas1,
                        password2: This.pas2,
                        yzmcode: This.code,
                        nickname: This.nickname,
                        type: 1
                    }, function(data) {
                        This.jiazai = false;
                        _toast(data.msg);
                        if (data.status == 1) {
                            if (this.title == '修改密码') {
                                setTimeout(function() {
                                    var web = _openHref({
                                        url: 'index.html',
                                        id: 'index',
                                        close: true
                                    });
                                    setTimeout(function() {
                                        web.evalJS("back()");
                                    }, 200);
                                }, 1000);
                            } else {
                                //忘记密码
                                setTimeout(function() {
                                    _close();
                                }, 1000);
                            }
                        }
                    });

                }
            }
        });
    </script>
</body>

</html>